<html>
<head><meta charset="utf-8"><title>Why does this code in rustc_target not trigger an error? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html">Why does this code in rustc_target not trigger an error?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217824927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20this%20code%20in%20rustc_target%20not%20trigger%20an%20error%3F/near/217824927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html#217824927">(Nov 24 2020 at 22:57)</a>:</h4>
<p>Just scrolling through some code, and I noticed that Rust Analyzer was flagging a <code>match</code> as an error, but <code>rustc</code> compiles it without errors.</p>
<p>In <code>compiler/rustc_target/src/asm/mod.rs</code>:</p>
<div class="codehilite"><pre><span></span><code>impl InlineAsmReg {
    pub fn name(self) -&gt; &amp;&#39;static str {
        match self {
            Self::X86(r) =&gt; r.name(),
            Self::Arm(r) =&gt; r.name(),
            Self::AArch64(r) =&gt; r.name(),
            Self::RiscV(r) =&gt; r.name(),
            Self::Hexagon(r) =&gt; r.name(),
            Self::Mips(r) =&gt; r.name(),
        }
    }
</code></pre></div>
<p>But <code>InlineAsmReg</code> defines other variants that aren't included in this <code>match</code>, like <code>Nvptx</code>. Why does this compile?</p>



<a name="217825363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20this%20code%20in%20rustc_target%20not%20trigger%20an%20error%3F/near/217825363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html#217825363">(Nov 24 2020 at 23:02)</a>:</h4>
<p>Because those enums are uninhabited <a href="https://github.com/rust-lang/rust/blob/74459930a951db7a68b3ecd86f3b796339e59fe5/compiler/rustc_target/src/asm/nvptx.rs#L48">https://github.com/rust-lang/rust/blob/74459930a951db7a68b3ecd86f3b796339e59fe5/compiler/rustc_target/src/asm/nvptx.rs#L48</a></p>



<a name="217825384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20this%20code%20in%20rustc_target%20not%20trigger%20an%20error%3F/near/217825384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html#217825384">(Nov 24 2020 at 23:02)</a>:</h4>
<p>...and that crate uses <code>#![feature(exhaustive_patterns)]</code></p>



<a name="217825399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20this%20code%20in%20rustc_target%20not%20trigger%20an%20error%3F/near/217825399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html#217825399">(Nov 24 2020 at 23:03)</a>:</h4>
<p>Ahhh, ok.  So RA just has a different view of things than rustc does.</p>



<a name="217825436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20this%20code%20in%20rustc_target%20not%20trigger%20an%20error%3F/near/217825436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html#217825436">(Nov 24 2020 at 23:03)</a>:</h4>
<p>r-a does not implement the unstable exhaustiveness checks</p>



<a name="217825460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20this%20code%20in%20rustc_target%20not%20trigger%20an%20error%3F/near/217825460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20this.20code.20in.20rustc_target.20not.20trigger.20an.20error.3F.html#217825460">(Nov 24 2020 at 23:03)</a>:</h4>
<p>or at least not all of them, it has a partial/buggy implementation of or-patterns</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>